//InsureSandpayModel
//2020-08-28 11:07:31

package models

import (
	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/common/models/base"
	"git.900sui.cn/kc/kcgin/orm"
)

//表结构体
type InsureSandpayModel struct {
	Model *base.Model
	Field InsureSandpayModelField
}

//表字段
type InsureSandpayModelField struct {
	T_table        string `default:"insure_sandpay"`
	F_id           string `default:"id"`
	F_insure_id    string `default:"insure_id"`
	F_acct_name    string `default:"acct_name"`
	F_acct_no      string `default:"acct_no"`
	F_bank_name    string `default:"bank_name"`
	F_bank_no      string `default:"bank_no"`
	F_bank_card_no string `default:"bank_card_no"`
	F_ctime        string `default:"ctime"`
}

//初始化
func (i *InsureSandpayModel) Init(ormer ...orm.Ormer) *InsureSandpayModel {
	functions.ReflectModel(&i.Field)
	i.Model = base.NewModel(i.Field.T_table, ormer...)
	return i
}

//新增数据
func (i *InsureSandpayModel) Insert(data map[string]interface{}) int {
	result, _ := i.Model.Data(data).Insert()
	return result
}

// 根据insureIds批量获取数据
func (i *InsureSandpayModel) GetListByInsureIds(insureIds []int) []map[string]interface{} {
	if len(insureIds) == 0 {
		return []map[string]interface{}{}
	}
	return i.Model.Where(map[string]interface{}{
		i.Field.F_insure_id: []interface{}{"in", insureIds},
	}).Select()
}

//
func (i *InsureSandpayModel) GetByInsureId(insureId int) map[string]interface{} {
	if insureId <= 0 {
		return map[string]interface{}{}
	}
	return i.Model.Where([]base.WhereItem{
		{
			Field: i.Field.F_insure_id,
			Value: insureId,
		},
	}).Find()
}
